package ru.geyes.screw.collections;

import ru.geyes.screw.closures.Function2V;
import ru.geyes.screw.closures.Function2P;
import ru.geyes.screw.closures.Function2B;
import ru.geyes.screw.closures.Function;

import java.util.concurrent.ConcurrentHashMap;
import java.util.Collection;

/**
 * @author alex
 * @date 17.02.2009
 */
public class ConcurrentHashMapX<K, V> extends ConcurrentHashMap<K, V> implements MapX<K,V> {

    public ListX<V> flatMap() {
        ListX<V> list = new ArrayListX<V>();
        for (V v : this.values()) {
            ListX<V> result;
            if (v instanceof Collection) {
                Collection c = (Collection)v;
                result = new ArrayListX<V>(c);
            }
            else if (v instanceof OptionX) {
                OptionX<V> c = (OptionX)v;
                if (c.isDefined())
                    result = ListXUtil.wrap(c.get());
                else
                    result = ListXUtil.emptyListX();
            } else {
                result = ListXUtil.wrap(v);
            }
            list.addAll(result);
        }
        return list;
    }

    public Option<V> getO(K key) {
        return null;
    }

    public ListX<V> valuesX() {
        return null;
    }

    public void forAll(Function2V<K, V> exec) {

    }

    public MapX<K, V> filter(Function2B<K, V> filterF) {
        return null;
    }

    public V getOrPut(K key, Function<V> closure) {
        return null;
    }

    public <P> MapX<K, P> map(Function2P<P, K, V> mapper) {
        return null;
    }
}
